public class MyTerr {

    static class TreeNode {

        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }

    public TreeNode creatTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');

        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        E.right = H;

        return A;

    }

    public void qianTree(TreeNode p) {
        if (p == null) {
            return;
        }
        System.out.print(p.val + " ");
        qianTree(p.left);
        qianTree(p.right);
    }

    public void zhongTree(TreeNode p) {
        if (p == null) {
            return;
        }
        zhongTree(p.left);
        System.out.print(p.val + " ");
        zhongTree(p.right);
    }

    public void houTree(TreeNode p) {
        if (p == null) {
            return;
        }
        houTree(p.left);
        houTree(p.right);
        System.out.print(p.val + " ");
    }

    public static int sizenode;
    public int size(TreeNode p) {
        if (p == null) {
            return 0;
        }
        sizenode++;
        size(p.left);
        size(p.right);
        return sizenode;
    }

    public static int leafsize;
    public int getLeafNodeCount(TreeNode p) {
        if (p == null) {
            return 0;
        }
        if (p.left == null && p.right == null) {
            leafsize++;

        }
        getLeafNodeCount(p.left);
        getLeafNodeCount(p.right);
        return leafsize;
    }
}
